﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UniMana.Utils.Controls;
using UniMana.Data;

namespace UniMana.Data
{
    public class Graduate_ExamSubjectInfo
    {
        #region /*Không thay đổi*/
            public bds m_bds = new bds();

            public void Save()
            {
                m_bds.EndEdit();
                m_data.m_DCSave.SubmitChanges();
            }

            #endregion /*Không thay đổi*/
            private DBMain m_data = new DBMain();
            #region [Properties - Thuộc tính]
            public Graduate_ExamSubject Properties
            {
                get { return m_bds.Current as Graduate_ExamSubject; }
            }
            #endregion

            public Graduate_ExamSubjectInfo(string _strExamKey)
            {
                var Iquery = m_data.m_DCSave.Graduate_ExamSubjects.Where(p => p.Graduate_ExamKey == Convert.ToInt32(_strExamKey));
                m_bds.DataSource = Iquery;
                var Row = Iquery.FirstOrDefault();
                if (Row == null)
                {
                    Graduate_ExamSubject exam = new Graduate_ExamSubject();
                    exam.Graduate_ExamKey = Convert.ToInt32(_strExamKey);
                    Row = exam;
                    //m_bds.Add(Row);
                    //m_bds.MoveLast();
                }
            }

            public Graduate_ExamSubjectInfo(int _iSubjectExamKey)
            {
                var Iquery = m_data.m_DCSave.Graduate_ExamSubjects.Where(p => p.Graduate_SubjectExamKey == _iSubjectExamKey);
                m_bds.DataSource = Iquery;
                var Row = Iquery.FirstOrDefault();
                if (Row == null)
                {
                    Graduate_ExamSubject examSubject = new Graduate_ExamSubject();
                    examSubject.Graduate_SubjectExamKey = _iSubjectExamKey;
                    Row = examSubject;
                    m_bds.Add(Row);
                    //m_bds.MoveLast();
                }
            }

            public Graduate_ExamSubjectInfo(int subjectExamKey = 0, int examKey =0)
            {
                var Iquery = m_data.m_DCSave.Graduate_ExamSubjects.Where(p => p.Graduate_SubjectExamKey == subjectExamKey && p.Graduate_ExamKey == examKey);
                m_bds.DataSource = Iquery;
                var Row = Iquery.FirstOrDefault();
                if (Row == null)
                {
                    Graduate_ExamSubject examSubject = new Graduate_ExamSubject();
                    examSubject.Graduate_SubjectExamKey = subjectExamKey;
                    Row = examSubject;
                    m_bds.Add(Row);
                    //m_bds.MoveLast();
                }
            }
            public void Delete()
            {
                m_bds.DeleteCurrent();
            }
    }
}
